/**************************************************************************************
* StatusPanel.java
* 
*************************************************************************************/
package creid.mythos.ui;

import java.awt.Graphics;

import creid.mythos.shared.PlayerStatus;


public class StatusPanel extends GamePanel
{

	//Constants/////////////////////////////////////////////////////////////////////////

	private static final long serialVersionUID = 8729569996634309622L;
	static final int WIDTH = GameUI.FONT_HORIZONTAL_SPACING * 20;
	static final int HEIGHT = GameUI.FONT_VERTICAL_SPACING * 40;
	
	//Status panel character width
	private static final int X_OFFSET = 2;
	private static final int Y_OFFSET = GameUI.FONT_VERTICAL_SPACING + 3;
	
	//Status left-hand sides
	private static final String L_BIO = "Level ";
	private static final String L_XP = "EXP";
	private static final String L_ATTACK = "Fighting";
	private static final String L_DEFENSE = "Defense";
	private static final String L_HEALTH = "Health";

	//Attributes////////////////////////////////////////////////////////////////////////
	
	private char[] name;
	private char[] bio;
	private char[] xp;
	private char[] health;
	private char[] attack;
	private char[] defense;
	private int condition;
	
	//Constructors//////////////////////////////////////////////////////////////////////

	public StatusPanel()
	{
		setSize(WIDTH, HEIGHT);
		
		name = new char[0];
		bio = new char[0];
		xp = new char[0];
		health = new char[0];
		attack = new char[0];
		defense = new char[0];
		condition = PlayerStatus.CON_HEALTHY;
	}
	
	//Methods///////////////////////////////////////////////////////////////////////////
	
	void updateState(PlayerStatus data)
	{
		
		name = data.getName().toCharArray();
		bio = (L_BIO + data.getLevel() + " " + data.getRole()).toCharArray();
		xp = (L_XP + " " + data.getXP()).toCharArray();
		health = (L_HEALTH + " " + data.getHealthStatus()).toCharArray();
		attack = (L_ATTACK + " " + data.getAttackStatus()).toCharArray();
		defense = (L_DEFENSE + " " + data.getDefenseStatus()).toCharArray();
		condition = data.getCondition();
	}
	
	@Override
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		
		if (name.length == 0)
			return;
		
		//Name, rank and level number
		g.setColor(GameUI.colors.get(ColorData.LIGHT_BLUE));
		
		//Name
		g.drawChars(name, 0, name.length, X_OFFSET, Y_OFFSET);
		
		//Level X Role
		g.drawChars(bio, 0, bio.length, X_OFFSET, Y_OFFSET * 2);
		
		g.setColor(GameUI.colors.get(ColorData.WHITE));
		g.drawChars(xp, 0, xp.length, X_OFFSET, Y_OFFSET * 4);
		
		g.drawChars(attack, 0, attack.length, X_OFFSET, Y_OFFSET * 6);
		g.drawChars(defense, 0, defense.length, X_OFFSET, Y_OFFSET * 7);
		
		if (condition <= PlayerStatus.CON_LOW_HEALTH)
			g.setColor(GameUI.colors.get(ColorData.RED));
		else if (condition == PlayerStatus.CON_INJURED)
			g.setColor(GameUI.colors.get(ColorData.YELLOW));
		else
			g.setColor(GameUI.colors.get(ColorData.GREEN));
		
		g.drawChars(health, 0, health.length, X_OFFSET, Y_OFFSET * 9);
	}
}
